package com.fejal.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.Range;

@Entity
public class TurmaOferta implements Serializable{

	private static final long serialVersionUID = -2045888846035185377L;

	@Id
	@GeneratedValue (strategy = GenerationType.AUTO)
	private int codigoTurmaOferta;
	
	@Range(min=1, max=2)
	private int semestre;

	@Range(min=1950, max=2999)
	private int ano;
	
	@Range(min=0, max=200)
	private int vagas;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "codigoTurma", insertable = true, updatable = true)
	@Fetch(FetchMode.JOIN)
	@Cascade(CascadeType.SAVE_UPDATE)
	private Turma turma;
	
	@OneToMany(mappedBy="turmaOferta", fetch = FetchType.LAZY)
	@Cascade({   
        CascadeType.ALL,   
        CascadeType.DELETE_ORPHAN})   
	private Collection<TurmaOfertaDisciplina> turmaOfertaDisciplina;
	
	public TurmaOferta(){
		
	}


	public int getCodigoTurmaOferta() {
		return codigoTurmaOferta;
	}


	public void setCodigoTurmaOferta(int codigoTurmaOferta) {
		this.codigoTurmaOferta = codigoTurmaOferta;
	}


	public int getSemestre() {
		return semestre;
	}


	public void setSemestre(int semestre) {
		this.semestre = semestre;
	}


	public int getAno() {
		return ano;
	}


	public void setAno(int ano) {
		this.ano = ano;
	}


	public int getVagas() {
		return vagas;
	}


	public void setVagas(int vagas) {
		this.vagas = vagas;
	}


	public Turma getTurma() {
		return turma;
	}


	public void setTurma(Turma turma) {
		this.turma = turma;
	}

	public Collection<TurmaOfertaDisciplina> getTurmaOfertaDisciplina() {
		return turmaOfertaDisciplina;
	}


	public void setTurmaOfertaDisciplina(
			Collection<TurmaOfertaDisciplina> turmaOfertaDisciplina) {
		this.turmaOfertaDisciplina = turmaOfertaDisciplina;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ano;
		result = prime * result + codigoTurmaOferta;
		result = prime * result + semestre;
		result = prime * result + ((turma == null) ? 0 : turma.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TurmaOferta other = (TurmaOferta) obj;
		if (ano != other.ano)
			return false;
		if (codigoTurmaOferta != other.codigoTurmaOferta)
			return false;
		if (semestre != other.semestre)
			return false;
		if (turma == null) {
			if (other.turma != null)
				return false;
		} else if (!turma.equals(other.turma))
			return false;
		return true;
	}
	
}
